package org.corolla.cloth.web.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.corolla.cloth.entity.Order;
import org.corolla.cloth.service.OrderService;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage(value = "struts-default")
@Results({
          @Result(name = "input", type = "redirect", location = "/view/Pay.jsp"),
          @Result(name = "success", type = "redirect", location = "/view/PaySucess.jsp") })
@Namespace("/view")
@Action(value = "payAction")
public class PayAction extends ActionSupport {

    @Resource(name = "orderService")
    private OrderService orderService;

    private String       total;
    private String       count;
    private String       orderTotal;

    @Override
    public String execute() throws Exception {
    	orderService=new OrderService();
        // 程序运行到execute()时，前面的验证都已经正确了
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();
       
        List<Order> orderlist = orderService.findAllOrders();
  
        try {
            if (null != orderlist) {
                if (orderlist.size() > 0) {
                    for (int i = 0; i < orderlist.size(); i++) {

                        orderService.removeOrderByPk(orderlist.get(i).getId());
                    }
                }

            }
            session.setAttribute("orderlist", null);
            session.setAttribute("orderPricelist", null);
            session.setAttribute("orderTotal",0);
            session.setAttribute("totalcountprice",0);
            session.setAttribute("transportfees", 0);
            session.setAttribute("totelprice",0);
            session.setAttribute("unitPrice", 0);
            session.setAttribute("totalcountprice", 0);

          
            return SUCCESS;
        } catch (Exception ex) {
            ex.printStackTrace();
            return "input";
        }
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public String getCount() {
        return count;
    }

    public void setCount(String count) {
        this.count = count;
    }

    public String getOrderTotal() {
        return orderTotal;
    }

    public void setOrderTotal(String orderTotal) {
        this.orderTotal = orderTotal;
    }

}
